const express = require('express');
const multer = require('multer');
const images = express.Router()
const fs = require("fs");
const path=require('path')
const upload = multer({dest:__dirname +'/uploads'})
images.use(upload.any()) 


//上传个人头像图片
images.post('/', async (req, res, next) => {
  const files = req.files
  console.log(files)
  let oldfile = req.files[0].path
  let newfile = req.files[0].path +path.parse(req.files[0].originalname).ext
  fs.renameSync(oldfile,newfile)
  res.send({
    err:0,
    msg:'上传文件成功',
    
    // url:"http://127.0.0.1:3000/upload/"+req.files[0].filename+path.parse(req.files[0].originalname).ext
    url:"http://47.119.123.95:3000/upload/"+req.files[0].filename+path.parse(req.files[0].originalname).ext
    // url:"http://119.91.84.179:3000/upload/"+req.files[0].filename+path.parse(req.files[0].originalname).ext
  })
});


module.exports = images